home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / examples / xpkdice.c < prev    next >
C/C++ Source or Header  |  1998-08-27  |  2KB  |  80 lines

  1. /* XPK - General XPK file-to-file packer/unpacker   */
  2. /* This is the version to be compiled with DICE     */
  3. /* Watch the special handing of the progress report */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <dos/dos.h>
  9. #include <xpk/xpk.h>
  10. #include <proto/xpkmaster.h>
  11.  
  12. extern hookstub();
  13.  
  14. struct Library *XpkBase, *OpenLibrary(UBYTE *libName, ULONG version);
  15. char errbuf[XPKERRMSGSIZE + 1];      /* +1 to make room for '\n'        */
  16.  
  17. __stkargs long chunkfunc(struct Hook *myhook, struct XpkProgress *prog)
  18. {
  19.   long i;
  20.   printf("\r%4s: %-9s %-12s (%6d bytes, %3d%% done, %2d%% CF, %6d cps) ",
  21.     prog->xp_PackerName,  prog->xp_Activity,  prog->xp_FileName,
  22.     prog->xp_ULen,        prog->xp_Done,      prog->xp_CF, prog->xp_Speed);
  23.   fflush(stdout);
  24.   if(prog->xp_Type == XPKPROG_END || (i = (long)
  25.   SetSignal(0, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C))
  26.     printf("\n");
  27.  
  28.   return i;
  29. }
  30.  
  31. struct Hook chunkhook = {{0},(void*)hookstub,(void*)chunkfunc};
  32.  
  33. struct TagItem tags[] = {
  34.     XPK_InName,    (long)NULL ,
  35.     XPK_OutName,   (long)NULL ,
  36.     XPK_GetError,  (long)NULL,
  37.     XPK_ChunkHook, (long)NULL,
  38.     XPK_Ignore,    (long)0    ,
  39.     XPK_NoClobber, (long)TRUE ,
  40.     TAG_DONE};
  41.  
  42.  
  43. void end(char *text)
  44. {
  45.   if(text)
  46.     Write(Output(), text, strlen(text));
  47.   if(XpkBase)
  48.     CloseLibrary(XpkBase);
  49.   exit(text ? 10 : 0);
  50. }
  51.  
  52. void main(int argc, char *argv[])
  53. {
  54.   int res;
  55.  
  56.   if(!(XpkBase=OpenLibrary(XPKNAME,0)))
  57.     end("Cannot open "XPKNAME"\n");
  58.     
  59.   if((argc < 3) || (argc > 4))
  60.     end("Usage: XPK [<method>] <infile> <outfile>\n");
  61.     
  62.   tags[0].ti_Data = (long)argv[argc-2]; /* First try to decompress... */
  63.   tags[1].ti_Data = (long)argv[argc-1];
  64.   tags[2].ti_Data = (long)errbuf;
  65.   tags[3].ti_Data = (long)&chunkhook;
  66.  
  67.   if(argc==3)
  68.     res=XpkUnpack(tags);
  69.   else
  70.   {
  71.     tags[4].ti_Tag = XPK_PackMethod;
  72.     tags[4].ti_Data= (long)argv[1];
  73.     res=XpkPack(tags);
  74.   }
  75.   if(res)
  76.     end(strcat(errbuf,"\n"));
  77.     
  78.   end(0);
  79. }
  80.